#include"UnitLR.h"

#include"Field.h"
#include"Map.h"

#include<stdio.h>

#include<QMap>

UnitLR::UnitLR(Map *map, UnitAge age, Team team):Unit(map, team, _getFullName(age), "LR", age){
	_initStats(age);
	m_hasRetaliated = true;
}

UnitLR::~UnitLR(){
	
}

//TODO: This could probably use some tweaking.
///Regardless, this should suffice for now.
double UnitLR::getAttackPriority(const Unit *unit)const{
	double priority = 0;
	priority += (10 - unit->health());
	if(unit->type() == TYPE_HM)
		priority += 10;
	priority += unit->attack(true)/100.0;
	priority -= unit->defense(true)/100.0;
	return priority;
}

int UnitLR::getFieldPriorityForField(Field *field)const{
	if(field->type() == FIELD_HILLS)
		return 2;
	return 0;
}

QString UnitLR::_getFullName(UnitAge age){
	switch(age){
		case AGE_BRZ:
			return "Stone Thrower";
		case AGE_IRN:
			return "Ballista";
		case AGE_EMA:
			return "Catapult";
		case AGE_HMA:
			return "Trebuchet";
		case AGE_LMA:
			return "Cannon";
		case AGE_CA:
			return "Field Gun";
		case AGE_IA:
			return "Breech Loader";
		default:
			return "Stone Thrower";
	}
}

void UnitLR::_initStats(UnitAge age){
	switch(age){
		case AGE_BRZ:
			m_attack = 3;
			m_defense = 2;
			m_range = 12;
			m_speed = 6;
			m_attackBonusHills = 1;
			m_attackBonusHM = 2;
			m_defenseBonusHM = 2;
			break;
		case AGE_IRN:
			m_attack = 5;
			m_defense = 3;
			m_range = 13;
			m_speed = 6;
			m_attackBonusHills = 2;
			m_attackBonusHM = 2;
			m_defenseBonusHM = 2;
			break;
		case AGE_EMA:
			m_attack = 7;
			m_defense = 3;
			m_range = 13;
			m_speed = 6;
			m_attackBonusHills = 3;
			m_attackBonusHM = 3;
			m_defenseBonusHM = 3;
			break;
		case AGE_HMA:
			m_attack = 10;
			m_defense = 4;
			m_range = 14;
			m_speed = 6;
			m_attackBonusHills = 3;
			m_attackBonusHM = 4;
			m_defenseBonusHM = 4;
			break;
		case AGE_LMA:
			m_attack = 13;
			m_defense = 4;
			m_range = 12;
			m_speed = 6;
			m_attackBonusHills = 4;
			m_attackBonusHM = 4;
			m_defenseBonusHM = 4;
			break;
		case AGE_CA:
			m_attack = 14;
			m_defense = 6;
			m_range = 15;
			m_speed = 8;
			m_attackBonusHills = 6;
			m_attackBonusHM = 7;
			m_defenseBonusHM = 7;
			break;
		case AGE_IA:
			m_attack = 20;
			m_defense = 9;
			m_range = 15;
			m_speed = 8;
			m_attackBonusHills = 9;
			m_attackBonusHM = 10;
			m_defenseBonusHM = 10;
			break;
	}
}

int UnitLR::attackTerrainBonus()const{
	if(field()->type() == FIELD_HILLS)
		return m_attackBonusHills;
	return 0;
}

int UnitLR::defenseBonusAgainst(UnitType type)const{
	if(type == TYPE_HM)
		return m_defenseBonusHM;
	return 0;
}

int UnitLR::attackBonusAgainst(UnitType type)const{
	int bonus = 0;
	if(field()->type() == FIELD_HILLS)
		bonus += m_attackBonusHills;
	if(type == TYPE_HM)
		bonus += m_attackBonusHM;
	return bonus;
}

/*	switch(age){
		case AGE_BRZ:
			break;
		case AGE_IRN:
			break;
		case AGE_EMA:
			break;
		case AGE_HMA:
			break;
		case AGE_LMA:
			break;
		case AGE_CA:
			break;
		case AGE_IA:
			break;
		default:
			break;
	}*/ 
 
 
